Telegram Group & Telegram Channel
🔎 Команда дня: быстрый рецепт профилирования с cProfile и pstats

🔍 Профилирование — это способ найти узкие места в производительности кода.

Вы можете точно узнать, какие функции тормозят выполнение, где тратится больше всего времени, и какие вызовы стоит оптимизировать.

Python поставляется с двумя встроенными профайлерами:
🔴 cProfile — написан на C, работает быстрее и точнее,
🔴 profile — на Python, обычно медленнее.

✔️ Обычно выбираем cProfile для измерения производительности.

Как профилировать скрипт


1️⃣ Запустите скрипт с профилированием и сохраните результат в файл:
python -m cProfile -o profile my_script.py


2️⃣ Для анализа результатов используйте модуль pstats:
python -m pstats profile <<< $'sort cumtime\nstats 1000' | less


🔴 sort cumtime — сортируем функции по кумулятивному времени (время выполнения функции плюс все вызовы внутри неё)
🔴 stats 1000 — показываем первые 1000 строк статистики
🔴 less — удобный просмотр с прокруткой (нажмите q для выхода)

Полезные опции

✔️ Профилируйте модули через -m:
python -m cProfile -o profile -m module_name [args]


✔️ Для сравнения результатов до и после оптимизации используйте разные имена файлов:
python -m cProfile -o before.profile script.py
python -m cProfile -o after.profile script.py


Можно менять сортировку по другим метрикам:

🔴 time — время выполнения только самой функции
🔴 calls — количество вызовов функции (может помочь найти «горячие» участки)

Библиотека питониста #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/pyproglib/6801
Create:
Last Update:

🔎 Команда дня: быстрый рецепт профилирования с cProfile и pstats

🔍 Профилирование — это способ найти узкие места в производительности кода.

Вы можете точно узнать, какие функции тормозят выполнение, где тратится больше всего времени, и какие вызовы стоит оптимизировать.

Python поставляется с двумя встроенными профайлерами:
🔴 cProfile — написан на C, работает быстрее и точнее,
🔴 profile — на Python, обычно медленнее.

✔️ Обычно выбираем cProfile для измерения производительности.

Как профилировать скрипт


1️⃣ Запустите скрипт с профилированием и сохраните результат в файл:

python -m cProfile -o profile my_script.py


2️⃣ Для анализа результатов используйте модуль pstats:
python -m pstats profile <<< $'sort cumtime\nstats 1000' | less


🔴 sort cumtime — сортируем функции по кумулятивному времени (время выполнения функции плюс все вызовы внутри неё)
🔴 stats 1000 — показываем первые 1000 строк статистики
🔴 less — удобный просмотр с прокруткой (нажмите q для выхода)

Полезные опции

✔️ Профилируйте модули через -m:
python -m cProfile -o profile -m module_name [args]


✔️ Для сравнения результатов до и после оптимизации используйте разные имена файлов:
python -m cProfile -o before.profile script.py
python -m cProfile -o after.profile script.py


Можно менять сортировку по другим метрикам:

🔴 time — время выполнения только самой функции
🔴 calls — количество вызовов функции (может помочь найти «горячие» участки)

Библиотека питониста #буст

BY Библиотека питониста | Python, Django, Flask


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/pyproglib/6801

View MORE
Open in Telegram


Библиотека питониста | Python Django Flask Telegram | DID YOU KNOW?

Date: |

For some time, Mr. Durov and a few dozen staffers had no fixed headquarters, but rather traveled the world, setting up shop in one city after another, he told the Journal in 2016. The company now has its operational base in Dubai, though it says it doesn’t keep servers there.Mr. Durov maintains a yearslong friendship from his VK days with actor and tech investor Jared Leto, with whom he shares an ascetic lifestyle that eschews meat and alcohol.

Telegram and Signal Havens for Right-Wing Extremists

Since the violent storming of Capitol Hill and subsequent ban of former U.S. President Donald Trump from Facebook and Twitter, the removal of Parler from Amazon’s servers, and the de-platforming of incendiary right-wing content, messaging services Telegram and Signal have seen a deluge of new users. In January alone, Telegram reported 90 million new accounts. Its founder, Pavel Durov, described this as “the largest digital migration in human history.” Signal reportedly doubled its user base to 40 million people and became the most downloaded app in 70 countries. The two services rely on encryption to protect the privacy of user communication, which has made them popular with protesters seeking to conceal their identities against repressive governments in places like Belarus, Hong Kong, and Iran. But the same encryption technology has also made them a favored communication tool for criminals and terrorist groups, including al Qaeda and the Islamic State.

Библиотека питониста | Python Django Flask from tw


Telegram Библиотека питониста | Python, Django, Flask
FROM USA